<?php

class timuModule extends Model
{
    public function __construct()
    {
        parent::__construct("timu");
    }

    /**
     * 查列表
     * @date: 2019年6月18日 下午2:26:19
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function getallList()
    {
        $timuxuanxiangM = new Model("timuxuanxiang");
        $parameterM = new parameterModel();

        $relist = [];
        $fenleilist = $parameterM->getparameterArrayByclassid("441");
        foreach ($fenleilist as $k1 => $v1) {
            if ($v1['value'] == '4'){
                continue;
            }
            $relistItem['fenlei_name'] = $v1['name'];
            $relistItem['fenlei_value'] = $v1['value'];
            //查询题目
            $list = $this->where("fenlei='{$v1['value']}' ")->orderBy(" paixu asc,id desc ")->all();
            foreach ($list as $k => $v) {
                //查询题目
                $xuanxianglist = $timuxuanxiangM->where("laiyuanbianhao='{$v['xuanxiang']}'")->orderBy(" paixu asc,id asc ")->all();
                unset($v['xuanxiang']);
                $v['xuanxianglist'] = $xuanxianglist;
                $list[$k] = $v;
            }
            $relistItem['fenlei_timulist'] = $list;
            $relist[] = $relistItem;
        }
        return $relist;
    }

    public function getListByids($ids)
    {
        $timuxuanxiangM = new Model("timuxuanxiang");
        //查询题目
        $list = $this->where("fenlei = '4' and id in ({$ids}) ")->orderBy(" paixu asc,id desc ")->all();
        foreach ($list as $k => $v) {
            //查询题目
            $xuanxianglist = $timuxuanxiangM->where("laiyuanbianhao='{$v['xuanxiang']}'")->orderBy(" paixu asc,id desc ")->all();
            unset($v['xuanxiang']);
            $v['xuanxianglist'] = $xuanxianglist;
            $list[$k] = $v;
        }
        return $list;
    }

    /**
     * 提取json里的题目ID
     * @date: 2019年6月24日 上午11:02:30
     * @param:  [{"timu":"1","xuanxiang":"2"},{"timu":"2","xuanxiang":"3"}]
     * @return:
     * @author: 龚华尧
     */
    public function getIdsByJsonstr($data)
    {
        $timuid = "";
        foreach ($data as $k => $v) {
            if ($timuid == "") {
                $timuid = $v["timu"];
            } else {
                $timuid = $timuid . "," . $v["timu"];
            }
        }
        return $timuid;
    }

}